﻿using System.Data;
using OpenXmlEasy.Basic;
using OpenXmlEasy.Word;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            const string filename = @"D:\temp\test3.docx";
            //using (var ms = new MemoryStream())
            //{
            //    using (var fs = new FileStream(filename, FileMode.OpenOrCreate))
            //    {
            //        var we = new WordEasy(ms);

            //        we.InsertContent("hello world!");
            //        we.Save();

            //        var length = (int)ms.Length;
            //        var data = new byte[length];
            //        ms.Position = 0;
            //        ms.Read(data, 0, length);
            //        fs.Write(data, 0, length);
            //    }
            //}
            using (var we = new WordEasy(filename))
            {
                we.AddDirecotryPlaceholder();
                we.InsertBreak();
                we.InsertContent("hello world!");
                var dt = CreateTable();
                we.InsertTitle("柱状图", true);
                we.InsertTitle("小标题", 2, true);
                we.InsertTitle("小标题2", 2);
                we.InsertChart(ChartType.Column, dt.Columns[0], new[] { 1, 2 });
                we.InsertTitle("条状图");
                we.InsertChart(ChartType.Bar, dt.Columns[0], new[] { 2, 2 });
                we.InsertTitle("线形图");
                we.InsertChart(ChartType.Line, dt.Columns[0], new[] { 1, 2, 3 });
                we.InsertTitle("雷达图");
                we.InsertChart(ChartType.Radar, dt.Columns[0], new[] { 1, 2, 3 });
                we.InsertTitle("饼状图");
                we.InsertChart(ChartType.Pie, dt.Columns[0], 2);
                we.AddDirectory();
                we.Save();
            }
        }

        private static DataTable CreateTable()
        {
            var dt = new DataTable();
            dt.Columns.Add("");
            dt.Columns.Add("系列1");
            dt.Columns.Add("系列2");
            dt.Columns.Add("系列3");
            {
                var row = dt.NewRow();
                row[0] = "类别1";
                row[1] = 2.8;
                row[2] = 4;
                row[3] = 12;
                dt.Rows.Add(row);
            }
            {
                var row = dt.NewRow();
                row[0] = "类别2";
                row[1] = 1;
                row[2] = 5;
                row[3] = 18;
                dt.Rows.Add(row);
            }
            {
                var row = dt.NewRow();
                row[0] = "类别3";
                row[1] = 3;
                row[2] = 9;
                row[3] = 1;
                dt.Rows.Add(row);
            }
            {
                var row = dt.NewRow();
                row[0] = "类别4";
                row[1] = 5.1;
                row[2] = 3;
                row[3] = 8;
                dt.Rows.Add(row);
            }
            return dt;
        }
    }
}
